/*
 * Created by JFormDesigner on Fri May 20 11:50:12 CST 2022
 */

package jw3.c9.view;

import jw3.c9.controller.Userinfocontroller;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

/**
 * @author Brainrain
 */
public class Login extends JFrame {
    public Login() {
        initComponents();
        this.setVisible(true);
        this.setSize(800,600);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
        String Number=textField1.getText();
        String pwd=new String(passwordField1.getPassword());
        if (!Number.equals("")&&!pwd.equals("")){
            if (Userinfocontroller.login(Number,pwd)){
                JOptionPane.showMessageDialog(null
                        ,"登录成功！");
            }else{
                JOptionPane.showMessageDialog(null,"账号密码错误！");
            }}
        else     {
            JOptionPane.showMessageDialog(null,"账号或密码不能为空");
        }

    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        dialogPane = new JPanel();
        contentPanel = new JPanel();
        label1 = new JLabel();
        textField1 = new JTextField();
        label2 = new JLabel();
        passwordField1 = new JPasswordField();
        button1 = new JButton();
        button2 = new JButton();
        button3 = new JButton();
        buttonBar = new JPanel();
        okButton = new JButton();
        cancelButton = new JButton();

        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== dialogPane ========
        {
            dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
            dialogPane.setLayout(new BorderLayout());

            //======== contentPanel ========
            {
                contentPanel.setLayout(null);

                //---- label1 ----
                label1.setText("\u8d26\u53f7\uff1a");
                contentPanel.add(label1);
                label1.setBounds(new Rectangle(new Point(45, 35), label1.getPreferredSize()));
                contentPanel.add(textField1);
                textField1.setBounds(95, 30, 145, textField1.getPreferredSize().height);

                //---- label2 ----
                label2.setText("\u5bc6\u7801\uff1a");
                contentPanel.add(label2);
                label2.setBounds(new Rectangle(new Point(50, 65), label2.getPreferredSize()));
                contentPanel.add(passwordField1);
                passwordField1.setBounds(105, 65, 130, passwordField1.getPreferredSize().height);

                //---- button1 ----
                button1.setText("\u767b\u5f55");
                button1.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        button1MouseClicked(e);
                    }
                });
                contentPanel.add(button1);
                button1.setBounds(new Rectangle(new Point(40, 115), button1.getPreferredSize()));

                //---- button2 ----
                button2.setText("\u6ce8\u518c");
                contentPanel.add(button2);
                button2.setBounds(new Rectangle(new Point(160, 120), button2.getPreferredSize()));

                //---- button3 ----
                button3.setText("\u5fd8\u8bb0\u5bc6\u7801");
                contentPanel.add(button3);
                button3.setBounds(new Rectangle(new Point(290, 125), button3.getPreferredSize()));

                {
                    // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < contentPanel.getComponentCount(); i++) {
                        Rectangle bounds = contentPanel.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = contentPanel.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    contentPanel.setMinimumSize(preferredSize);
                    contentPanel.setPreferredSize(preferredSize);
                }
            }
            dialogPane.add(contentPanel, BorderLayout.CENTER);

            //======== buttonBar ========
            {
                buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
                buttonBar.setLayout(new GridBagLayout());
                ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};
                ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};

                //---- okButton ----
                okButton.setText("OK");
                buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 5), 0, 0));

                //---- cancelButton ----
                cancelButton.setText("Cancel");
                buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 0), 0, 0));
            }
            dialogPane.add(buttonBar, BorderLayout.SOUTH);
        }
        contentPane.add(dialogPane, BorderLayout.CENTER);
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel dialogPane;
    private JPanel contentPanel;
    private JLabel label1;
    private JTextField textField1;
    private JLabel label2;
    private JPasswordField passwordField1;
    private JButton button1;
    private JButton button2;
    private JButton button3;
    private JPanel buttonBar;
    private JButton okButton;
    private JButton cancelButton;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
